home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / sgml / unix / sgmlc / sgmlxtrn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-03  |  13.3 KB  |  236 lines

  1. /******************************************************************************/
  2. /*    Standard Generalized Markup Language Users' Group (SGMLUG)
  3.                  SGML Parser Materials (ARCSGML 1.0)
  4.  
  5. (C) 1983-1988 Charles F. Goldfarb (assigned to IBM Corporation)
  6. (C) 1988-1991 IBM Corporation
  7.  
  8. Licensed to the SGML Users' Group for distribution under the terms of
  9. the following license:                                                        */
  10.  
  11. char license[297] =
  12. "SGMLUG hereby grants to any user: (1) an irrevocable royalty-free, \
  13. worldwide, non-exclusive license to use, execute, reproduce, display, \
  14. perform and distribute copies of, and to prepare derivative works \
  15. based upon these materials; and (2) the right to authorize others to \
  16. do any of the foregoing.";
  17. /******************************************************************************/
  18. #include "sgmlincl.h"         /* #INCLUDE statements for SGML parser. */
  19. /******************************************************************************/
  20. /* SGMLXTRN: Storage allocation and initialization for all public variables.
  21.              Exceptions: Constants lex????? and del????? are defined in
  22.              LEX?????.C modules; constants pcb????? are defined in PCB?????.c.
  23. */
  24. /******************************************************************************/
  25. /* Variables to be initialized each pass (except first, which is done by C).
  26. */
  27. int badresw = 0;              /* 1=REF_ out of context; 0=valid. */
  28. int charmode = 0;             /* >0=in #CHARS; 0=not. */
  29. int conactsw = 0;             /* 1=return saved content action 0=get new one.*/
  30. int conrefsw = 0;             /* 1=content reference att specified; 0=no. */
  31. int contersv = 0;             /* Save contersw while processing pending REF. */
  32. int contersw = 0;             /* 1=element or #CHARS out of context; 0=valid. */
  33. int datarc = 0;               /* Return code for data: DAF_ or REF_. */
  34. int delmscsw = 0;             /* 1=DELMSC must be read on return to es==0. */
  35. int didreq = 0;               /* 1=required implied tag processed; 0=no. */
  36. int dostag = 0;               /* 1=retry newetd instead of parsing; 0=parse. */
  37. int dtdsw = 0;                /* DOCTYPE declaration found: 1=yes; 0=no. */
  38. int entdatsw = 0;             /* 2=CDATA entity; 4=SDATA; 8=NDATA; 0=none. */
  39. int entpisw = 0;              /* 4=PI entity occurred; 0=not. */
  40. int eodsw = 0;                /* 1=eod found in error; 0=not yet. */
  41. int eofsw = 0;                /* 1=eof found in body of document; 0=not yet. */
  42. int es = -1;                  /* Index of current source in stack. */
  43. int etagimct = 0;             /* Implicitly ended elements left on stack. */
  44. int etagimsw = 0;             /* 1=end-tag implied by other end-tag; 0=not. */
  45. int etagmin = MINNONE;        /* Minim: NONE NULL NET DATA; implied by S/ETAG*/
  46. int etictr = 0;               /* Number of "NET enabled" tags on stack. */
  47. int etisw = 0;                /* 1=tag ended with eti; 0=did not. */
  48. int indtdsw = 0;              /* Are we in the DTD? 1=yes; 0=no. */
  49. int mslevel = 0;              /* Nesting level of marked sections. */
  50. int msplevel = 0;             /* Nested MS levels subject to special parse. */
  51. int newdtdsw = 0;             /* 1=DTD just started; 0=DTD returned to TP. */
  52. int prologsw = 1;             /* 1=in prolog; 0=not. */
  53. int pss = 0;                  /* SGMLACT: scbsgml stack level. */
  54. int sgmlsw = 0;               /* SGML declaration found: 1=yes; 0=no. */
  55. int stagmin = MINNONE;        /* Minimization: NONE, NULL tag, implied by STAG*/
  56. int tagctr = 0;               /* Tag source chars read. */
  57. int ts = -1;                  /* Index of current tag in stack. */
  58. struct parse *propcb = &pcbpro;    /* Current PCB for prolog parse. */
  59. /******************************************************************************/
  60. /* Variables that do not require general initialization each pass, because
  61.    they (1) contain values that are set in the first pass and used in all of
  62.    them, or (2) are initialized (if necessary) by the functions that use them.
  63. */
  64. int aentctr = 0;              /* Number of ENTITY tokens in this att list. */
  65. int conact = 0;               /* Return code from content parse. */
  66. int conrefsv = 0;             /* Save conrefsw when doing implied start-tag.*/
  67. int dtdrefsw = 0;             /* External DTD? 1=yes; 0=no. */
  68. int etiswsv = 0;              /* Save etisw when processing implied start-tag.*/
  69. int grplvl = 0;               /* Current level of nested grps in model. */
  70. int idrctr = 0;               /* Number of IDREF tokens in this att list. */
  71. int mdessv = 0;               /* ES level at start of markup declaration. */
  72. int notadn = 0;               /* Position of NOTATION attribute in list. */
  73. int parmno = 0;               /* Current markup declaration parameter number. */
  74. int pass = 0;                 /* 0=first pass over file; >0=later passes. */
  75. int pexsw = 0;                /* 1=tag valid solely because of plus exception.*/
  76. int rcessv = 0;               /* ES level at start of RCDATA content. */
  77. int tagdelsw = 0;             /* 1=tag ended with delimiter; 0=no delimiter. */
  78. int tokencnt = 0;             /* Number of tokens found in attribute value. */
  79. long idrefl = 0;              /* Existence bits: IDREF atts (in same order). */
  80. struct entity *ecbdeflt = 0;  /* #DEFAULT ecb (NULL if no default entity). */
  81. struct etd *docetd = 0;       /* The etd for the document as a whole. */
  82. struct etd *etagreal = 0;     /* Actual or dummy etd that implied this tag. */
  83. struct etd *newetd = 0;       /* The etd for a start- or end-tag recognized. */
  84. struct etd *nextetd = 0;      /* ETD that must come next (only one choice). */
  85. struct etd *stagreal = 0;     /* Actual or dummy etd that implied this tag. */
  86. struct parse *conpcb = 0;     /* Current PCB for content parse. */
  87. UNCH *antvptr = 0;            /* Name token value returned by antvget. */
  88. UNCH *data = 0;               /* Pointer to returned data in buffer. */
  89. UNCH *mdname = 0;             /* Name of current markup declaration. */
  90. UNCH *ptcon = 0;              /* Current pointer into tbuf. */
  91. UNCH *ptpro = 0;              /* Current pointer into tbuf. */
  92. UNCH *pvalptr = 0;            /* Pointer to parsed attribute value. */
  93. UNCH *rbuf = 0;               /* DOS file read area (including RCC buffer). */
  94. UNCH *rbufs = 0;              /* DOS file read area: start position for read. */
  95. UNCH *subdcl = 0;             /* Subject of markup declaration (e.g., GI). */
  96. UNCH Tstart = 0;              /* Save starting token for AND group testing. */
  97. UNS conradn = 0;              /* 1=CONREF attribute in list (0=no). */
  98. UNS datalen = 0;              /* Length of returned data in buffer. */
  99. UNS entlen = 0;               /* Length of TAG or EXTERNAL entity text. */
  100. UNS idadn = 0;                /* Number of ID attribute (0 if none). */
  101. UNS noteadn = 0;              /* Number of NOTATION attribute (0 if none). */
  102. UNS pifldlen = 0;             /* Length of field in public identifier (EOS). */
  103. UNS reqadn = 0;               /* Num of atts with REQUIRED default (0=none). */
  104. /******************************************************************************/
  105. /* Variable arrays and structures: initialization not required for each pass.
  106. */
  107. char ntoabuf[4] = {0};        /* Buffer for returned string. */
  108. int *tprc;                    /* Pointer to text processor return code holder.*/
  109. UNIV *tprcbp;                 /* Pointer to text processor rcb pointer. */
  110. struct ad al[ATTCNT+2] = {0};   /* Current attribute list work area. */
  111. struct dcncb *dcntab[1] = {0};  /* List of data content notation names. */
  112. struct entity *aentl[GRPCNT] = {0};  /*ECBs for AENTITY tokens in an att list.*/
  113. struct entity *etab[ENTHASH] = {0};  /* Entity hash table. */
  114. struct etd *etdtab[ETDHASH] = {0};  /* Element type definition hash table. */
  115. struct fpi fpidf = {0};       /* Fpi for #DEFAULT entity. */
  116. struct id *itab[IDHASH] = {0};  /* Unique identifier hash table. */
  117. struct ipberr ie = {0};       /* IPB: From SGML for error handling services.*/
  118. struct ipbfile io = {0};      /* IPB: file I/O services from text processor.*/
  119. struct ipbmem im = {0};       /* IPB: memory services from text processor. */
  120. struct rcbdata rcbdaf = {SGMLDAF};    /* RCB: data, record end, pi, eod. */
  121. struct rcbtag rcbetag = {SGMLETG};    /* RCB: end-tag. */
  122. struct rcbtag rcbstag = {SGMLSTG};    /* RCB: start-tag. */
  123. struct restate scbsgml[TAGLVL+1] = {0};  /* SGMLACT: return action state stack. */
  124. struct source scbs[ENTLVL+1] = {0};  /* Stack of open sources ("SCB stack"). */
  125. struct srh *srhtab[1] = {0};  /* List of SHORTREF table headers. */
  126. struct stat ds = {0};         /* Document statistics. */
  127. struct switches sw = {0};     /* Parser control switches set by text proc. */
  128. struct tag tags[TAGLVL+1] = {0};   /* Stack of open elements ("tag stack"). */
  129. struct thdr gbuf[GRPGTCNT+2] = {0};  /* Buffer for creating group. */
  130. struct thdr prcon[3] = {0};   /* 0-2: Model for *DOC content. */
  131. struct thdr undechdr = {0};   /* 0:Default model hdr for undeclared content.*/
  132. UNCH dtype[NAMELEN+2] = {0};  /* Document type name. */
  133. UNCH entbuf[NAMELEN+2] = {0};   /* Buffer for entity reference name. */
  134. UNCH fce[2] = {0};            /* String form of FCE char (fce[1] must be EOS).*/
  135. UNCH nonchbuf[2] = {0};       /* Buffer for valid nonchar character reference.*/
  136. UNCH tbuf[ATTSPLEN+LITLEN+2];   /* Work area for tokenization. */
  137.  UNCH *lbuf = tbuf+ATTSPLEN;  /* In tbuf: Literal parse area; TAGLEN limit.*/
  138. /******************************************************************************/
  139. /* Constants.
  140. */
  141. struct map dctab[] = {        /* Keywords for declared content parameter.*/
  142.      syn.k.rcdata,  MRCDATA+MPHRASE,
  143.      syn.k.cdata,   MCDATA+MPHRASE,
  144.      syn.k.any,     MANY+MCHARS+MGI,
  145.      syn.k.empty,   MNONE+MPHRASE,
  146.      NULL,          0
  147. };
  148. struct map deftab[] = {       /* Default value keywords. */
  149.      syn.k.implied,  DNULL ,
  150.      syn.k.required, DREQ  ,
  151.      syn.k.current,  DCURR ,
  152.      syn.k.conref,   DCONR ,
  153.      syn.k.fixed,    DFIXED,
  154.      NULL,           0
  155. };
  156. struct map dvtab[] = {        /* Declared value: keywords and type codes.*/
  157. /*                                TYPE      NUMBER   */
  158. /*   grp             ANMTGRP      Case 1 0  Grp size */
  159. /*   grp member      ANMTGRP      Case   0  Position */
  160. /*   grp             ANOTEGRP     Case 1 1  Grp size */
  161.      syn.k.notation, ANOTEGRP, /* Case   1  Position */
  162.      syn.k.cdata,    ACHARS  , /* Case   2  Always 0 */
  163.      syn.k.entitee,  AENTITY , /* Case   3  Normal 1 */
  164.      syn.k.idiot,    AID     , /* Case   4  Normal 1 */
  165.      syn.k.idref,    AIDREF  , /* Case   5  Normal 1 */
  166.      syn.k.name,     ANAME   , /* Case   6  Normal 1 */
  167.      syn.k.nmtoken,  ANMTOKE , /* Case   7  Normal 1 */
  168.      syn.k.number,   ANUMBER , /* Case   8  Normal 1 */
  169.      syn.k.nutoken,  ANUTOKE , /* Case   9  Normal 1 */
  170.      syn.k.entities, AENTITYS, /* Case   A  Normal 1 */
  171.      syn.k.idrefs,   AIDREFS , /* Case   B  # tokens */
  172.      syn.k.names,    ANAMES  , /* Case   C  # tokens */
  173.      syn.k.nmtokens, ANMTOKES, /* Case   D  # tokens */
  174.      syn.k.numbers,  ANUMBERS, /* Case   E  # tokens */
  175.      syn.k.nutokens, ANUTOKES, /* Case   F  # tokens */
  176.      NULL,           0         /* Case   0  ERROR    */
  177. };
  178. struct map enttab[] = {       /* Entity declaration second parameter. */
  179.      syn.k.cdata,     ESC ,
  180.      syn.k.sdata,     ESX ,
  181.      syn.k.ms,        ESMS,
  182.      syn.k.pi,        ESI ,
  183.      syn.k.starttag,  ESS ,
  184.      syn.k.endtag,    ESE ,
  185.      syn.k.md,        ESMD,
  186.      NULL,            0
  187. };
  188. struct map exttab[] = {       /* Keywords for external identifier. */
  189.      syn.k.system,    EDSYSTEM,
  190.      syn.k.public,    EDPUBLIC,
  191.      NULL,            0
  192. };
  193. struct map extettab[] = {       /* Keywords for external entity type. */
  194.      syn.k.cdata,     ESNCDATA,
  195.      syn.k.ndata,     ESNNDATA,
  196.      syn.k.sdata,     ESNSDATA,
  197.      syn.k.subdoc,    ESNSUB,
  198.      NULL,            0
  199. };
  200. struct map funtab[] = {       /* Function character reference names. */
  201.      syn.k.re,       RECHAR,
  202.      syn.k.rs,       RSCHAR,
  203.      syn.k.tab,      TABCHAR,
  204.      syn.k.space,    SPCCHAR,
  205.      NULL,           0
  206. };
  207. struct map mstab[] = {        /* Marked section keywords. */
  208.      syn.k.temp,    MSTEMP  ,
  209.      syn.k.include, MSTEMP  , /* Treat INCLUDE like TEMP; both are NOPs.*/
  210.      syn.k.rcdata,  MSRCDATA,
  211.      syn.k.cdata,   MSCDATA ,
  212.      syn.k.ignore,  MSIGNORE,
  213.      NULL,          0
  214. };
  215. struct map pubcltab[] = {     /* Keywords for public text class. */
  216.      syn.k.capacity,  FPICAP  ,
  217.      syn.k.charset,   FPICHARS,
  218.      syn.k.document,  FPIDOC  ,
  219.      syn.k.dtd,       FPIDTD  ,
  220.      syn.k.elements,  FPIELEM ,
  221.      syn.k.entities,  FPIENT  ,
  222.      syn.k.lpd,       FPILPD  ,
  223.      syn.k.nonsgml,   FPINON  ,
  224.      syn.k.notation,  FPINOT  ,
  225.      syn.k.shortref,  FPISHORT,
  226.      syn.k.subdoc,    FPISUB  ,
  227.      syn.k.syntax,    FPISYN  ,
  228.      syn.k.text,      FPITEXT ,
  229.      NULL,            0
  230. };
  231. UNCH indefent[10] = "\12#DEFAULT";   /* Internal name: default entity name. */
  232. UNCH indefetd[10] = "\12*DOCTYPE";   /* Internal name: default document type. */
  233. UNCH indocent[10] = "\12*SGMLDOC";   /* Internal name: SGML document entity. */
  234. UNCH indocetd[6]  = "\6*DOC";        /* Internal name: document level etd. */
  235. UNCH indtdent[9]  = "\11*DTDENT";    /* Internal name: external DTD entity. */
  236.